package com.ruoyi.web.controller.laiqianba.merchant;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.db.domain.MerchantOperatorLog;
import com.ruoyi.merchant.service.IMerchantOperatorLogService;
import com.ruoyi.web.wrapper.MerchantOperatorLogWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 商户操作明细Controller
 * 
 * @author ruoyi
 * @date 2024-04-09
 */
@RestController
@RequestMapping("/merchant/log")
public class MerchantOperatorLogController extends BaseController
{
    @Autowired
    private IMerchantOperatorLogService merchantOperatorLogService;

    /**
     * 查询商户操作明细列表
     */
    @PreAuthorize("@ss.hasPermi('merchant:log:list')")
    @GetMapping("/list")
    public TableDataInfo list(MerchantOperatorLog merchantOperatorLog)
    {
        startPage();
        List<Map<String, Object>> list = merchantOperatorLogService.selectMerchantOperatorLogMapList(merchantOperatorLog);
        list = new MerchantOperatorLogWrapper(list).wrap();
        return getDataTable(list);
    }

    /**
     * 导出商户操作明细列表
     */
    @PreAuthorize("@ss.hasPermi('merchant:log:export')")
    @Log(title = "商户操作明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MerchantOperatorLog merchantOperatorLog)
    {
        List<MerchantOperatorLog> list = merchantOperatorLogService.selectMerchantOperatorLogList(merchantOperatorLog);
        ExcelUtil<MerchantOperatorLog> util = new ExcelUtil<MerchantOperatorLog>(MerchantOperatorLog.class);
        util.exportExcel(response, list, "商户操作明细数据");
    }

    /**
     * 获取商户操作明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('merchant:log:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(merchantOperatorLogService.selectMerchantOperatorLogById(id));
    }

    /**
     * 新增商户操作明细
     */
    @PreAuthorize("@ss.hasPermi('merchant:log:add')")
    @Log(title = "商户操作明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MerchantOperatorLog merchantOperatorLog)
    {
        return toAjax(merchantOperatorLogService.insertMerchantOperatorLog(merchantOperatorLog));
    }

    /**
     * 修改商户操作明细
     */
    @PreAuthorize("@ss.hasPermi('merchant:log:edit')")
    @Log(title = "商户操作明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MerchantOperatorLog merchantOperatorLog)
    {
        return toAjax(merchantOperatorLogService.updateMerchantOperatorLog(merchantOperatorLog));
    }

    /**
     * 删除商户操作明细
     */
    @PreAuthorize("@ss.hasPermi('merchant:log:remove')")
    @Log(title = "商户操作明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(merchantOperatorLogService.deleteMerchantOperatorLogByIds(ids));
    }
}
